<template>
  <div class="baseuser">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="用户名">
          <el-input v-model="param.username"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="loadBaseUser"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-button size="small" type="primary" icon="el-icon-upload2" @click="toAddHandler">新增</el-button>
      <el-button size="small" type="success" icon="el-icon-upload2" @click="downloadHandler">导出</el-button>
    </div>

    <!-- /按钮 -->
    <!-- {{baseusers}} -->
    <!-- 表格 -->
    <el-table size="small" :data="baseusers">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="头像" prop="userFace">
        <template slot-scope="scope">
          <div
            style="
              width: 100px;
              border-radius: 5px;
              height: 80px;
              over-flow: hidden;
            "
          >
            <img :src="scope.row.userFace" alt="" style="width: 100%" />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="用户名"
        prop="username"
        align="center"
      ></el-table-column>
      <el-table-column
        label="姓名"
        prop="realname"
        align="center"
      ></el-table-column>
      <el-table-column
        label="性别"
        prop="gender"
        align="center"
      ></el-table-column>
      <el-table-column
        label="状态"
        prop="status"
        align="center"
      ></el-table-column>
      <el-table-column
        label="电话"
        prop="telephone"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="editHandler(scope.row)"
            >修改</el-button
          >
          <el-button type="danger" icon="el-icon-delete" circle size="mini" @click="deleteHandler(scope.row)"
            >删除</el-button
        >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>

<script>
import { del, get } from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      param: {},
      baseusers: [],
    };
  },
  //页面渲染的时候会调用的函数
  created() {
    this.loadBaseUser();
  },
  methods: {
    downloadHandler(){
      window.location.href = "http://localhost:8888/module/download?name="+this.param.usename
    },
    //跳转修改页面
    editHandler(row) {
      this.$router.push({
        path: "/baseuser/create", //跳转的路由（前端）
        query: row, // 携带参数
      });
    },
    
    deleteHandler(row){
     this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/baseUser/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadBaseUser();
        });
      });
    },
    //跳转
    toAddHandler() {
      this.$router.push("/baseUser/create");
    },
    
    //查询后台的信息
    loadBaseUser() {
      let url = "http://localhost:8888/baseUser/query";
      get(url, this.param).then((resp) => {
        this.baseusers = resp.data;
      });
    },
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>>